﻿$(document).ready(function () {
    var clpsjgdata = new SmDataTable();
   

    var myClpsjg = new SmObjectData("SYS_CLPSJG");

    $('#clpsjggrid').datagrid({
        title: '储量评审机构', //列表的标题       
        iconCls: 'icon-ok',
        width: 'auto',
        height: 'auto',
        nowrap: false,
        striped: true,
        collapsible: true,
        singleSelect: true,
        sortName: 'BSM',
        sortOrder: 'asc',
        idField: 'BSM',
        rownumbers: true,
        columns: [[
            { field: 'BSM', title: '标识码', hidden: true },
            { field: 'NAME', title: '储量评审机构', width: '200' },
            { field: 'XZQDM', title: '所在行政区', width: '100' }
        ]],
        toolbar:
            [{
                text: '新增',
                iconCls: 'icon-add',
                handler: function () {
                    myClpsjg.Init("BSM", "");
                    GetValues();
                    $("#clpsjgdlg").dialog("open");
                }
            }, '-', {
                text: '修改',
                iconCls: 'icon-edit',
                handler: function () {
                    var node = $('#clpsjggrid').datagrid('getSelected');
                    if (node == null) {
                        $.messager.alert('提示', '请选择一行进行修改。');
                    } else {
                        myClpsjg.Init("BSM", node.BSM);
                        GetValues();
                    }
                    $("#clpsjgdlg").dialog("open");
                }
            }, '-', {
                text: '删除',
                iconCls: 'icon-remove',
                handler: function () {
                    var node = $('#clpsjggrid').datagrid('getSelected');
                    if (node == null) {
                        $.messager.alert('提示', '请选择一行进行修改。');
                    } else {
                        $.messager.confirm('警告', '确认要删除选中的储量评审机构吗?', function (r) {
                            if (r) {
                                myClpsjg.Init("BSM", node.BSM);
                                myClpsjg.Delete();
                                refreshgrid();
                            }
                        });

                    }
                }
            }, '-', {
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    refreshgrid();
                }
            }]
    });
    refreshgrid();
    function GetValues() {
        $("#clpsjgName").val(myClpsjg.GetValue("NAME"));
        $("#txtXZQDM").val(myClpsjg.GetValue("XZQDM"));
    }
    function SetValues() {
        myClpsjg.SetValue("NAME", $("#clpsjgName").val());
        myClpsjg.SetValue("XZQDM", $("#txtXZQDM").val());
    }
    function refreshgrid() {
        clpsjgdata.Init("select BSM,NAME,XZQDM from sys_clpsjg");
        $('#clpsjggrid').datagrid("loadData", clpsjgdata.GetEasyuiGridData());
    }

    $("#btnSave").click(function () {
        SetValues();
        myClpsjg.Update();
        refreshgrid()
        $("#clpsjgdlg").dialog("close");
    });

    $("#btnCance").click(function () {
        $("#clpsjgdlg").dialog("close");
    });
    
    

})